package com.szh.zx.duoxiancheng.asynctask;

import java.util.Timer;
import java.util.TimerTask;

/**TimerTask 延时任务
 * @author root
 */
public class TimerFixedDelay {
    static class LongRunningTask extends TimerTask{

        @Override
        public void run() {

            try {
                Thread.sleep(5_000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println("long running finished");
        }
    }
    static class FixedDelayTask extends TimerTask{

        @Override
        public void run() {
            System.out.println(System.currentTimeMillis());
        }
    }

    public static void main(String[] args) {
        Timer timer = new Timer();
        timer.schedule(new LongRunningTask(),10);
        timer.schedule(new FixedDelayTask(),1000);
    }
}
